package com.hbue.water.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hbue.water.entity.Customer;
import com.hbue.water.mapper.CustomerMapper;
import com.hbue.water.service.CustomerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author yushu
 * @date 2021/12/22
 * @apiNate
 */
@Service
@Slf4j
public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> implements CustomerService {

    @Autowired
    private CustomerMapper customerMapper;

    @Override
    public PageInfo<Customer> listCustomer(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Customer> customerList = customerMapper.selectList(null);
        return new PageInfo<>(customerList);
    }

    @Override
    public PageInfo<Customer> searchCustomer(Integer pageNum, Integer pageSize, String searchCondition) {
        PageHelper.startPage(pageNum, pageSize);
        QueryWrapper<Customer> qw = new QueryWrapper<>();
        if (StrUtil.isNotEmpty(searchCondition)) {
            qw.like("cust_name", searchCondition);
        }
        List<Customer> customerList = customerMapper.selectList(qw);
        return new PageInfo<>(customerList);
    }
}
